package factory.simple;

import factory.goods.*;
import factory.simple.SimplePizzaFactory;

/**
 * 工厂模式场景：摘自Head First。
 * 披萨店，生成披萨使用
 * User:xuzhidian
 * Date:2018/3/13
 * Time:22:05
 */
public class PizzaStore {
    private SimplePizzaFactory simplePizzaFactory;

    public PizzaStore(SimplePizzaFactory simplePizzaFactory) {
        this.simplePizzaFactory = simplePizzaFactory;
    }

    /**
     * 最简单的生产方式
     * 缺点：针对具体类编程，系统弹性差。
     *
     * @return
     */
    public IPizza orderPizza(String type) {
        IPizza pizza;
        if (type.equals("cheese")) {
            pizza = new CheesePizza();
        } else if (type.equals("greek")) {
            pizza = new GreekPizza();
        } else if (type.equals("pepperoni")) {
            pizza = new PepperoniPizza();
        } else {
            pizza = new Pizza();
        }
        pizza.prepare();
        pizza.bake();
        pizza.cut();
        pizza.box();
        return pizza;
    }

    /**
     * 使用简单工厂封装了判断的逻辑，让使用端使用更简单
     *
     * @param type
     * @return
     */
    public IPizza orderPizzaByFactory(String type) {
        IPizza pizza = simplePizzaFactory.createPizza(type);
        pizza.prepare();
        pizza.bake();
        pizza.cut();
        pizza.box();
        return pizza;
    }


}
